//
//  ZGBarChartViewController.m
//  扫码
//
//  Created by 鲍志刚 on 16/4/21.
//  Copyright © 2016年 鲍志刚. All rights reserved.
//

#import "ZGBarChartViewController.h"
#import "ZFChart.h"
#import "ZGStatisticsData.h"

@interface ZGBarChartViewController ()<ZFGenericChartDataSource,ZFBarChartDelegate>

@property (nonatomic, strong) NSArray *intervalDate;

@property (nonatomic, strong) NSArray *data;

@property (nonatomic, assign, getter = isCode) BOOL code;


@end

@implementation ZGBarChartViewController

-(NSArray *)intervalDate {
    
    if (_intervalDate == nil) {
        
        _intervalDate = [NSArray array];
        
    }
    
    return _intervalDate;
    
}

- (NSArray *)data {
    
    if (_data == nil) {
        
        _data = [NSArray array];
        
    }
    
    return  _data;
}


-(void)setStatisticData:(ZGStatisticsData *)statisticData {
    
    _statisticData = statisticData;
    
    self.intervalDate = statisticData.intervalDate;
    
    self.data = statisticData.data;
 
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
 
}

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.view.backgroundColor = [UIColor whiteColor];
    
    ZFBarChart * barChart = [[ZFBarChart alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATIONBAR_HEIGHT)];
    barChart.dataSource = self;
    barChart.delegate = self;
    barChart.topic = @"扫码人数统计";
    barChart.unit = @"人";
    barChart.topicColor = ZFPurple;
    //    barChart.isShowXLineValue = NO;
    //    barChart.backgroundColor = ZFGreen;
    //    barChart.valueLabelPattern = kPopoverLabelPatternBlank;
    //    barChart.isShowSeparate = YES;
    [self.view addSubview:barChart];
   
    [barChart strokePath];
    
    [ZGStatisticsData statisticsDataWithURL:@"SweepServlet?method=getSaveCount&startTime=2016-04-01&endTime=2016-04-07" successBlock:^(NSDictionary *dict) {
        
        ZGStatisticsData *statistic = [[ZGStatisticsData alloc] initWithDict:dict];
        
   

        self.data = dict[@"data"];
        self.intervalDate = dict[@"intervalDate"];
        
        self.data = statistic.data;
        
        self.intervalDate = statistic.intervalDate;
        
         [barChart strokePath];
//
    } errorBlock:^(NSError *e) {
        
    }];

}

#pragma mark - ZFGenericChartDataSource

- (NSArray *)valueArrayInGenericChart:(ZFGenericChart *)chart{
//    return @[@"100", @"375", @"0", @"486", @"195", @"337" ,@"234"];

    NSMutableArray *mArray = [NSMutableArray array];
    
    for (int i = 0; i < self.data.count; i++) {
        
        NSString *str = [NSString stringWithFormat:@"%@",self.data[i]];
        
        [mArray addObject:str];
    }
    
    
    return mArray.copy;
    
    /*[3,15,8,0,0,0,7]*/
}

- (NSArray *)nameArrayInGenericChart:(ZFGenericChart *)chart{
//    return @[@"16-04-01", @"16-04-02", @"16-04-03", @"16-04-04", @"16-04-05", @"16-04-06",@"16-04-07"];
    return self.intervalDate;
   
}

- (NSArray *)colorArrayInGenericChart:(ZFGenericChart *)chart{
    return @[ZFSkyBlue];
}

- (CGFloat)yLineMaxValueInGenericChart:(ZFGenericChart *)chart{
    return 20;
}

- (NSInteger)yLineSectionCountInGenericChart:(ZFGenericChart *)chart{
    return 3;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
